package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.saas.domain.dao.StockSurplusRecordDao;
import com.xbongbong.saas.domain.entity.StockSurplusRecordEntity;
import com.xbongbong.saas.model.StockSurplusRecordModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author lee
 * @date  2019-01-28 9:11
 **/
@Service("stockSurplusRecordModel")
public class StockSurplusRecordModelImpl implements StockSurplusRecordModel {
    @Resource
    private StockSurplusRecordDao stockSurplusRecordDao;
    /**
     * 根据索引查询数据
     *
     * @param param 查询参数
     * @return List<StockSurplusRecordEntity>
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     **/
    @Override
    public List<StockSurplusRecordEntity> findEntitys(Map<String, Object> param) {
        return stockSurplusRecordDao.findEntitys(param);
    }
    /**
     * 入库单产品数据插入
     * @param stockSurplusRecordEntity 供应商实体
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     * @return Integer
     */
    @Override
    public Integer insert(StockSurplusRecordEntity stockSurplusRecordEntity) {
        stockSurplusRecordEntity.setAddTime(DateTimeUtil.getInt());
        stockSurplusRecordEntity.setUpdateTime(DateTimeUtil.getInt());
        return stockSurplusRecordDao.insert(stockSurplusRecordEntity);
    }
    /**
     * 入库单产品数据更新
     * @param stockSurplusRecordEntity 供应商实体
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     * @return Integer
     */
    @Override
    public Integer update(StockSurplusRecordEntity stockSurplusRecordEntity) {
        stockSurplusRecordEntity.setUpdateTime(DateTimeUtil.getInt());
        return stockSurplusRecordDao.update(stockSurplusRecordEntity);
    }
    /**
     * 入库单产品数据保存
     * @param stockSurplusRecordEntity 保存实体
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     * @throws XbbException 异常
     * @return Integer
     */
    @Override
    public Integer save(StockSurplusRecordEntity stockSurplusRecordEntity) {
        if (stockSurplusRecordEntity.getId() == null || stockSurplusRecordEntity.getId().equals(0L)) {
            return insert(stockSurplusRecordEntity);
        }
        return update(stockSurplusRecordEntity);
    }

    @Override
    public void insertBatch(List<StockSurplusRecordEntity> stockSurplusRecordEntityList) throws XbbException {
        stockSurplusRecordDao.insertBatch(stockSurplusRecordEntityList);
    }

    @Override
    public List<StockSurplusRecordEntity> getLatestFlowBillByWarehouseKey(Map<String, Object> param) {
        return stockSurplusRecordDao.getLatestFlowBillByWarehouseKey(param);
    }

    @Override
    public void updateBatch(List<StockSurplusRecordEntity> list, String corpid) throws XbbException {
        stockSurplusRecordDao.updateBatch(list, corpid);
    }

    @Override
    public void deleteAllByCorpId(String corpid) {
        stockSurplusRecordDao.deleteAllByCorpId(corpid);
    }

    @Override
    public void insertRecordsFromProductWarehouse(String corpid, Long date) {
        stockSurplusRecordDao.insertRecordsFromProductWarehouse(corpid, date);
    }

    @Override
    public void batchInsertRecordsFromProductWarehouse(Map<String, Object> param) {
        stockSurplusRecordDao.batchInsertRecordsFromProductWarehouse(param);
    }

    @Override
    public void deleteByAddTime(Map<String, Object> param) {
        stockSurplusRecordDao.deleteByAddTime(param);
    }
}
